package com.yonyou.service.impl;

import com.yonyou.dao.BaseDao;
import com.yonyou.exception.BusinessException;
import com.yonyou.service.IDaoService;
import java.util.ArrayList;
import java.util.List;

public class DaoServiceImpl
  implements IDaoService
{
  private BaseDao dao;

  public DaoServiceImpl()
    throws BusinessException
  {
    this.dao = BaseDao.getInstance();
  }

  public boolean testConnection(String username, String password, String url)
  {
    return this.dao.TestConnection(username, password, url);
  }

  public Object queryMaxValue(String tableName, String columnName)
  {
    return this.dao.queryMaxValue(tableName, columnName);
  }

  public boolean updatePassword(String newPassword, String username)
  {
    String sql = "UPDATE hr_db_users SET password = '" + newPassword + "' where username='" + username + "'";
    try {
      this.dao.updateData(sql);
    } catch (BusinessException e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }

  public List<Object> executeQuery(String sql, Class clazz)
  {
    return this.dao.executeQuery(sql, clazz);
  }

  public boolean updateZhangtao(String code)
  {
    try {
      this.dao.delteData("hr_db_zhangtao");
      ArrayList list = new ArrayList();
      list.add(new Object[] { code });
      this.dao.insertBatchArray("insert into hr_db_zhangtao(code) values(?)", list);
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }
}